﻿// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");

using Newtonsoft.Json;
using System.Text;
using System.Xml.Linq;
using webClient;

//var url = "http://127.0.0.1:8888/light";
//string jsonStr = "{\"Name\":\"TOP_L1\",\"Intensity\":100}";

////var url = "http://127.0.0.1:8888/plc";

////"PCB板长度","PCB板厚度","上相机基准位置","下相机基准位置"

////"开始","停止","复位"
////
////"循环模式","背景光源启用"

////string jsonStr = "{\"Name\":\"PCB板长度\",\"FloatValue\":100}";
////string jsonStr = "{\"Name\":\"开始\"}";
////string jsonStr = "{\"Name\":\"循环模式\",\"BoolValue\":false}";


var url = "http://127.0.0.1:8888";
//url=http://127.0.0.1:8888/plc;
string jsonStr = "{\"Name\":\"TOP_L1\"Intensity\":100}";

var msg1 = new ClientMsg();
var msg2 = new ClientMsg();
var msg3 = new ClientMsg();

msg1.PLCList = new List<PLCData>();
msg1.PLCList.Add(new PLCData() { Name = PLCCmd.开始.ToString() });
msg1.PLCList.Add(new PLCData() { Name = PLCCmd.PCB板长度.ToString(), FloatValue = 100 });

msg2.LightList = new List<LightData>();
msg2.LightList.Add(new LightData() { Name = "TOP_L1", Intensity = 100 });
msg2.LightList.Add(new LightData() { Name = "TOP_L2", Intensity = 100 });

msg3.LightList = new List<LightData>();
msg3.LightList.Add(new LightData() { Name = "BOT_L1", Intensity = 100 });
msg3.LightList.Add(new LightData() { Name = "BOT_L2", Intensity = 100 });

string msgStr1 = JsonConvert.SerializeObject(msg1);
string msgStr2 = JsonConvert.SerializeObject(msg2);
string msgStr3 = JsonConvert.SerializeObject(msg3);


//var Obj = JsonConvert.DeserializeObject<ClientMsg>(msgStr);


//byte[] data = Encoding.UTF8.GetBytes(jsonStr);

CustomClient cClient = new CustomClient(url);

cClient.PostMsg(msgStr1).Wait();
cClient.PostMsg(msgStr2).Wait();
cClient.PostMsg(msgStr3).Wait();


//await t1.ContinueWith(async x =>await t2.ContinueWith(async x => await t3));
//await t1.ContinueWith(async x => await cClient.PostMsg(msgStr2).ContinueWith(
//    async x => await cClient.PostMsg(msgStr3))
//);

//HttpContent content = new StringContent(jsonStr, Encoding.UTF8,"application/json");
